package org.creativor.rayson.transport.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import org.creativor.rayson.demo.proxy.DemoTransferArgument;
import org.creativor.rayson.transport.api.TimeLimitConnection;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The class <code>ListenerTest</code> contains tests for the class
 * <code>{@link Listener}</code>.
 * <p>
 * Copyright Creativor Studio (c) 2011
 * 
 * @generatedBy CodePro at 11-5-7 上午2:57
 * @author Nick Zhang
 * @version $Revision: 1.0 $
 */
public class ListenerTest {
	/**
	 * Launch the test.
	 * 
	 * @param args
	 *            the command line arguments
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	public static void main(String[] args) {
		new org.junit.runner.JUnitCore().run(ListenerTest.class);
	}

	/**
	 * Perform pre-test initialization.
	 * 
	 * @throws Exception
	 *             if the initialization fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Before
	public void setUp() throws Exception {
		// TODO: add additional set up code here
	}

	/**
	 * Perform post-test clean-up.
	 * 
	 * @throws Exception
	 *             if the clean-up fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@After
	public void tearDown() throws Exception {
		// TODO: add additional tear down code here
	}

	/**
	 * Run the SelectionKey accept(SocketChannel,TimeLimitConnection) method
	 * test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testAccept_1() throws Exception {
		Listener fixture = new Listener(new ConnectionManager());
		SocketChannel socketChannel = SocketChannel.open();
		TimeLimitConnection clientConnection = new ClientStreamConnection(
				new InetSocketAddress(1), new DemoTransferArgument(""),
				new ConnectionManager());

		SelectionKey result = fixture.accept(socketChannel, clientConnection);

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.lang.NullPointerException
		// at
		// org.creativor.rayson.transport.client.Listener.accept(Listener.java:129)
		assertNotNull(result);
	}

	/**
	 * Run the SelectionKey accept(SocketChannel,TimeLimitConnection) method
	 * test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testAccept_2() throws Exception {
		Listener fixture = new Listener(new ConnectionManager());
		SocketChannel socketChannel = SocketChannel.open();
		TimeLimitConnection clientConnection = new ClientStreamConnection(
				new InetSocketAddress(1), new DemoTransferArgument(""),
				new ConnectionManager());

		SelectionKey result = fixture.accept(socketChannel, clientConnection);

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.lang.NullPointerException
		// at
		// org.creativor.rayson.transport.client.Listener.accept(Listener.java:129)
		assertNotNull(result);
	}

	/**
	 * Run the SelectionKey accept(SocketChannel,TimeLimitConnection) method
	 * test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testAccept_3() throws Exception {
		Listener fixture = new Listener(new ConnectionManager());
		SocketChannel socketChannel = SocketChannel.open();
		TimeLimitConnection clientConnection = new ClientStreamConnection(
				new InetSocketAddress(1), new DemoTransferArgument(""),
				new ConnectionManager());

		SelectionKey result = fixture.accept(socketChannel, clientConnection);

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.lang.NullPointerException
		// at
		// org.creativor.rayson.transport.client.Listener.accept(Listener.java:129)
		assertNotNull(result);
	}

	/**
	 * Run the void initialize() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testInitialize_1() throws Exception {
		Listener fixture = new Listener(new ConnectionManager());

		fixture.initialize();

		// TODO: add additional test code here
	}

	/**
	 * Run the void initialize() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testInitialize_2() throws Exception {
		Listener fixture = new Listener(new ConnectionManager());

		fixture.initialize();

		// TODO: add additional test code here
	}

	/**
	 * Run the Listener(ConnectionManager) constructor test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testListener_1() throws Exception {
		ConnectionManager connectionManager = new ConnectionManager();

		Listener result = new Listener(connectionManager);

		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals("Thread[Client listener,1,main]", result.toString());
		assertEquals(false, result.isInterrupted());
		assertEquals("Client listener", result.getName());
		assertEquals(0, result.countStackFrames());
		assertEquals(5074L, result.getId());
		assertEquals(1, result.getPriority());
		assertEquals(false, result.isAlive());
		assertEquals(true, result.isDaemon());
	}

	/**
	 * Run the void run() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testRun_1() throws Exception {
		Listener fixture = new Listener(new ConnectionManager());

		fixture.run();

		// TODO: add additional test code here
	}
}